package com.liqi.monitor.service.impl;

import com.liqi.common.annotation.DataScope;
import com.liqi.common.utils.DateUtils;
import com.liqi.common.utils.StringUtils;
import com.liqi.deployment.domain.DvDeployment;
import com.liqi.deployment.mapper.DvDeploymentMapper;
import com.liqi.monitor.domain.DvDeploymentSystem;
import com.liqi.monitor.domain.DvWorkOrder;
import com.liqi.monitor.mapper.DvDeploymentSystemMapper;
import com.liqi.monitor.mapper.DvWorkOrderMapper;
import com.liqi.monitor.service.IDvWorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 工单Service业务层处理
 *
 * @author zhanghan
 * @date 2022-10-17
 */
@Service
public class DvWorkOrderServiceImpl implements IDvWorkOrderService {

    @Autowired
    private DvWorkOrderMapper dvWorkOrderMapper;
    @Autowired
    private DvDeploymentMapper dvDeploymentMapper;

    @Override
    @DataScope(deptAlias = "d", userAlias = "u", regionAlias = "r", groupAlias = "g")
    public List<DvWorkOrder> selectWorkOrderList(DvWorkOrder dvWorkOrder) {
        return dvWorkOrderMapper.selectDvWorkOrderList(dvWorkOrder);
    }

    /**
     * 新增工单
     *
     * @param dvWorkOrder 工单
     * @return 结果
     */
    @Override
    public int insertDvWorkOrder(DvWorkOrder dvWorkOrder)
    {
    	DvDeployment dvDeployment = dvDeploymentMapper.selectDvDeploymentByDeviceId(dvWorkOrder.getDeviceId());
    	dvWorkOrder.setDeptId(dvDeployment.getDeptId());
        dvWorkOrder.setCreateUserId(dvWorkOrder.getOperationUserCode());
        dvWorkOrder.setCreateTime(DateUtils.getNowDate());
        dvWorkOrder.setOrderStatus(0);
        return dvWorkOrderMapper.insertDvWorkOrder(dvWorkOrder);
    }
    /**
     * 查询工单管理
     *
     * @param id 故障日志管理主键
     * @return 故障日志管理
     */
    @Override
    public DvWorkOrder selectDvWorkOrderById(Long id)
    {
        return dvWorkOrderMapper.selectDvWorkOrderById(id);
    }

    @Override
    public int deleteDvWorkOrder(Long[] ids) {
        return dvWorkOrderMapper.deleteDvWorkOrder(ids);
    }

    @Override
    public int updateDvWorkOrder(DvWorkOrder dvWorkOrder) {
        dvWorkOrder.setUpdateTime(DateUtils.getNowDate());
        return dvWorkOrderMapper.updateDvWorkOrder(dvWorkOrder);
    }
    @Override
    public int handleDvWorkOrder(DvWorkOrder dvWorkOrder) {
        dvWorkOrder.setDealTime(DateUtils.getNowDate());
        return dvWorkOrderMapper.handleDvWorkOrder(dvWorkOrder);
    }



}
